Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Use specific netlink families for android #75

Merged
merged 2 commits into from
Aug 30, 2019

Conversation

gfanton
Copy link
Contributor

@gfanton gfanton commented Aug 29, 2019

Hi there !

I work at Berty and actually use this lib along with libp2p on mobile.
Since a recent change and more particularly since the introduction of netlink for the reuse port, we can't use this lib anymore on Android.

Android doesn't allow netlink_xfrm & netlink_nflog in his base policy in enforce mode (see here).
this cause a permission denied when NewTransport method is called on android:

type=1400 audit(0.0:98079): avc: denied { create } for scontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tcontext=u:r:untrusted_app:s0:c182,c256,c512,c768 tclass=netlink_xfrm_socket permissive=0

However it's look like that only netlink route is needed, so we tried to limit netlink
families support on android build to NETLINK_ROUTE only when netlink.NewHandle is called, it seems good enough in our case and don’t cause any error anymore! 😄

I know you have no need to support android, but this change should not impact you since it will only build on android. Also, to be honnest, i'm not sure I understand all the implication of this change, it’s maybe not the good way to go, I’d like your advice on the subject.

Android doesn't allow netlink_xfrm & netlink_nflog in his base policy in enforce
mode. (see [here](https://android.googlesource.com/platform/system/sepolicy/+/3aa1c1725ea2b6fd452c5771629dcfc50a351538/public/app.te#396))
this cause a _permission denied_ when NewTransport method is called on android,
however it's look like that only *netlink route* is needed, so we just have to limit netlink
families support on android build to NETLINK_ROUTE only when netlink.NewHandle is called.
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Given that we're only using this for routes, how about we limit this to unix.NETLINK_ROUTE on all platforms? That should be strictly better (and it saves us a few sockets).

@Stebalien
Copy link
Member

I know you have no need to support android, but this change should not impact you since it will only build on android.

We definitely want to support Android, we just don't test on android... Please file patches and/or bugs like this whenever you find something that doesn't work on android.

Also, to be honnest, i'm not sure I understand all the implication of this change, it’s maybe not the good way to go, I’d like your advice on the subject.

This change looks correct. We're using netlink to find the correct socket when dialing some remote address.

@gfanton
Copy link
Contributor Author

gfanton commented Aug 30, 2019

Nice! however we still need a build constraint here since unix.NETLINK_* are not available on non-linux platform, so i've just renamed android to linux (android match linux constraint as well)

We definitely want to support Android, we just don't test on android... Please file patches and/or bugs like this whenever you find something that doesn't work on android.

I will! But don't worry too much, this is a rare case, other libp2p libs works pretty well on mobile (ios/android)

@Stebalien Stebalien merged commit 17543aa into libp2p:master Aug 30, 2019
@Stebalien
Copy link
Member

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants